package dataPersistence.dto;


import hitExceptions.InvalidDataException;
import coreModel.Barcode;
import coreModel.HIT;
import coreModel.ProductContainer;
import coreModel.ProductGroup;
import coreModel.Supply;
import dataPersistence.dto.ProductContainerDTO;

/**
 * Inherits from DataTransferObject
 *
 */
public class ProductGroupDTO  extends ProductContainerDTO implements DataTransferObject<ProductGroup> 
{

	private float threeMonthsSize;
	private String threeMonthUnit;


	public ProductGroupDTO(ProductGroup productGroup) 
	{
		convertFromModelObject(productGroup);
	}

	public ProductGroupDTO() 
	{
		//do nothing
	}

	@Override
	public ProductGroup convertToModelObject()
	{
		ProductContainer parent;

		if (super.getParentID()!=null)
		{
			parent = HIT.getInstance().getStorageUnitManager().getContainerByID(super.getParentID());
		}
		else 
			parent=null;
		try
		{
			ProductContainer tmp = new ProductGroup(super.getName(),parent,new Supply(threeMonthsSize, ProductDTO.toUnit(threeMonthUnit)));
			tmp.setContainerID( new Barcode(super.getProductContainerID()));
			return (ProductGroup) tmp;

		} 
		catch (InvalidDataException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public void convertFromModelObject(ProductGroup modelObject)
	{
		super.setParentID(modelObject.getContainerID().toString());
		super.setName(modelObject.getName());
		if(modelObject.getParent()!=null)
			super.setParentID(modelObject.getParent().getID());
		else
			super.setParentID(null);

		super.setProductContainerID(modelObject.getID());
		threeMonthsSize=modelObject.getThreeMonths().getSupplySize();
		threeMonthUnit=modelObject.getThreeMonths().getSupplyUnit().toString();


	}

	/**
	 * @return the threeMonthsSize
	 */
	public float getThreeMonthsSize()
	{
		return threeMonthsSize;
	}

	/**
	 * @param threeMonthsSize the threeMonthsSize to set
	 */
	public void setThreeMonthsSize(float threeMonthsSize)
	{
		this.threeMonthsSize = threeMonthsSize;
	}

	/**
	 * @return the threeMonthUnit
	 */
	public String getThreeMonthUnit()
	{
		return threeMonthUnit;
	}

	/**
	 * @param threeMonthUnit the threeMonthUnit to set
	 */
	public void setThreeMonthUnit(String threeMonthUnit)
	{
		this.threeMonthUnit = threeMonthUnit;
	}







}
